"""add ai_model

Revision ID: 26d5a3306732
Revises: c0672c65a35d
Create Date: 2025-04-08 17:03:33.192513

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision: str = '26d5a3306732'
down_revision: Union[str, None] = 'c0672c65a35d'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('ai_model',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('ai_api_id', sa.Integer(), nullable=False),
    sa.Column('model', sa.String(length=255), nullable=False, comment='模型名称'),
    sa.Column('description', sa.String(length=255), nullable=False, comment='描述'),
    sa.Column('status', sa.String(length=16), server_default=sa.text("'enabled'"), nullable=False, comment='状态'),
    sa.Column('created_at', sa.TIMESTAMP(), nullable=False),
    sa.Column('updated_at', sa.TIMESTAMP(), nullable=False),
    sa.ForeignKeyConstraint(['ai_api_id'], ['ai_api.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_ai_model_id'), 'ai_model', ['id'], unique=False)
    op.alter_column('ai_agents', 'system_prompt',
               existing_type=mysql.LONGTEXT(collation='utf8mb4_general_ci'),
               type_=sa.TEXT(length=16777216),
               existing_nullable=True)
    op.alter_column('ai_api', 'status',
               existing_type=mysql.INTEGER(),
               type_=sa.String(length=16),
               nullable=False,
               comment='状态',
               existing_comment='状态[1:草稿,0:完成]')
    op.alter_column('ai_api', 'created_at',
               existing_type=mysql.DATETIME(),
               type_=sa.TIMESTAMP(),
               nullable=False)
    op.alter_column('ai_api', 'updated_at',
               existing_type=mysql.DATETIME(),
               type_=sa.TIMESTAMP(),
               nullable=False)
    op.alter_column('funcall_log', 'log_text',
               existing_type=mysql.LONGTEXT(collation='utf8mb4_general_ci'),
               type_=sa.TEXT(length=16777216),
               existing_comment='日志信息',
               existing_nullable=True)
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('funcall_log', 'log_text',
               existing_type=sa.TEXT(length=16777216),
               type_=mysql.LONGTEXT(collation='utf8mb4_general_ci'),
               existing_comment='日志信息',
               existing_nullable=True)
    op.alter_column('ai_api', 'updated_at',
               existing_type=sa.TIMESTAMP(),
               type_=mysql.DATETIME(),
               nullable=True)
    op.alter_column('ai_api', 'created_at',
               existing_type=sa.TIMESTAMP(),
               type_=mysql.DATETIME(),
               nullable=True)
    op.alter_column('ai_api', 'status',
               existing_type=sa.String(length=16),
               type_=mysql.INTEGER(),
               nullable=True,
               comment='状态[1:草稿,0:完成]',
               existing_comment='状态')
    op.alter_column('ai_agents', 'system_prompt',
               existing_type=sa.TEXT(length=16777216),
               type_=mysql.LONGTEXT(collation='utf8mb4_general_ci'),
               existing_nullable=True)
    op.drop_index(op.f('ix_ai_model_id'), table_name='ai_model')
    op.drop_table('ai_model')
    # ### end Alembic commands ###
